﻿using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace DSAManager.Utils
{
   public class CharSetHelper
    {
        public static string HtmlDecode(string html)
        {
            return System.Web.HttpUtility.HtmlDecode(html);
        }

        public static string HtmlEncode(string html)
        {
            return System.Web.HttpUtility.HtmlEncode(html);
        }

        public static string UrlEncode(string str, Encoding encoding)
        {
            return HttpUtility.UrlEncode(str, encoding);
        }

        public static string UrlEncode(string str)
        {
            return UrlEncode(str, Encoding.UTF8);
        }

        public static string UrlDeCode(string str, Encoding encoding)
        {
            return HttpUtility.UrlDecode(str, encoding);
        }

        public static string UrlDeCode(string str)
        {
            return UrlDeCode(str, Encoding.UTF8);
        }

        public static string UnicodeToChinese(string str)
        {
            Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
            return reg.Replace(str, delegate(Match m)
                                        { return ((char) Convert.ToInt32(m.Groups[1].Value, 16)).ToString(); });
        }
    }
}
